package top.timous.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.timous.mapper.EpidemicMapper;
import top.timous.pojo.EpidemicInfo;
import top.timous.service.EpidemicService;
import top.timous.service.ProvinceService;
import top.timous.vo.EpidemicInfoVo;
import top.timous.vo.EpidemicTotalInfo;

import java.util.*;

@Service
public class EpidemicServiceImpl implements EpidemicService {
    @Autowired
    private EpidemicMapper epidemicMapper;
    @Autowired
    private ProvinceService provinceService;
    @Override
    public Map<String, Object> input(Integer userId , EpidemicInfoVo epidemicInfoVo) {
        List<EpidemicInfo> array = epidemicInfoVo.getArray();
        String date = epidemicInfoVo.getDate();
        String[] s = date.split("-");
        for (String s1 : s) {
            System.out.println(s1);
        }
        int year = Integer.parseInt(s[0]);
        int month = Integer.parseInt(s[1]);
        int day = Integer.parseInt(s[2]);
        for (EpidemicInfo epidemicInfo : array) {
            epidemicInfo.setDataDay(day);
            epidemicInfo.setDataMonth(month);
            epidemicInfo.setDataYear(year);
            epidemicInfo.setUserId(userId);
            epidemicInfo.setInputDate(new Date());
            System.out.println("========================");
            System.out.println(new Date());
            epidemicMapper.input(epidemicInfo);
        }
        /**
         * 存储完之后还要进行查询 ， 此时需要调用我们的查找省份的信息
         */
        return provinceService.noDataProvinceList(date);
    }

    @Override
    public Map<String, Object> EpidemicDetail() {
        Calendar calendar = new GregorianCalendar();
        /**
         * 根据日历类获取年月日
         */
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DATE);
        List<EpidemicTotalInfo> epidemicTotalInfos = epidemicMapper.EpidemicDetail(year, month, day);
        Map<String , Object> map = new HashMap<String, Object>();
        map.put("data" , epidemicTotalInfos);
        map.put("code" , 0);
        map.put("msg" , "请求成功！！");
        return map;
    }

    @Override
    public Map<String, Object> EpidemicDetails() {
        List<EpidemicTotalInfo> epidemicTotalInfos = epidemicMapper.EpidemicDetails();
        Map<String , Object> map = new HashMap<String, Object>();
        map.put("data" , epidemicTotalInfos);
        map.put("code" , 0);
        map.put("msg" , "请求成功！！");
        return map;
    }


}
